<template>
	<view class="page">
		<view class="tips">
			<text>请输入本人手机号码</text>
			<text>一个手机号码只能绑定一个用户</text>
		</view>

		<view class="input">
			<input type="text" placeholder="请输入手机号码" v-model="formData.username" />
		</view>
		<view class="input">
			<input type="password" placeholder="请输入密码" v-model="formData.password" />
		</view>

		<view class="btn" @tap="submit">
			提交
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import graceChecker from '@/common/graceChecker';
	export default {
		data() {
			return {
				formData: {
					username: '',
					password: ''
				}
			}
		},
		computed: {
			...mapState(['user'])
		},
		onLoad() {
			
		},
		methods: {
			async submit() {
				let formData = {
					username: this.formData.username,
					password: this.formData.password
				}
				var rule = [{
						name: 'username',
						checkType: 'notnull',
						errorMsg: '请输入手机号码'
					},
					{
						name: 'password',
						checkType: 'notnull',
						errorMsg: '请输入密码'
					}
				];
				var checkRes = graceChecker.check(formData, rule);
				if (checkRes) {
					let res = await this.$api.bindusername(formData);
					if (res.code == 1) {
						this.$wanlshop.msg('手机号绑定成功')
						this.$store.commit('user/setUser', {username:this.formData.username});
						setTimeout(() => {
							uni.navigateBack()
						}, 1500);
					}
				} else {
					this.$wanlshop.msg(graceChecker.error);
				}
			}
		}
	}
</script>
<style lang="less">
	page {
		background-color: #fff;
	}
</style>
<style lang="less" scoped>
	.page {
		.tips {
			padding-top: 60rpx;
			margin-bottom: 200rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			text {
				&:nth-child(1) {
					color: #333333;
					font-size: 48rpx;
					font-weight: 500;
				}

				&:nth-child(2) {
					color: #999999;
					font-size: 28rpx;
					margin-top: 12rpx;
				}
			}
		}

		.t {
			padding: 30rpx;
			color: #f00;
			font-size: 28rpx;
		}

		.input {
			box-shadow: 0 0 30px 0 rgba(43, 86, 112, .1);
			border-radius: 50rpx;
			width: 690rpx;
			height: 100rpx;
			padding: 0 30rpx;
			margin: 30rpx auto;

			input {
				height: 100%;
				font-size: 30rpx;
			}
		}

		.form {
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-top: 100rpx;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;

				text {
					margin-bottom: 20rpx;
					color: #333;
					font-size: 28rpx;
				}

				image {
					width: 300rpx;
					height: 207rpx;
				}
			}
		}
	}



	.btn {
		width: 510rpx;
		height: 84rpx;
		background: #FA802A;
		border-radius: 42rpx 42rpx 42rpx 42rpx;
		margin: 200rpx auto 0;
		line-height: 84rpx;
		text-align: center;
		color: #fff;
		font-size: 36rpx;
		font-weight: 500;
		
		&.disabled {
			background-color: #ccc;
			color: #fff;
		}
	}
</style>